Bash script does not work properly accross different terminals